#ifndef TEXTUREOBJECT_H
#define TEXTUREOBJECT_H

#include <string>
#include <vector>

#include "bga/system/Resource.h"

#include "bga/graphics/GLObject.h"


namespace bga
{

/*! \class TextureObject
*   \brief Class which define texture object
*/
class BOARD_HELL_ENGINE TextureObject : public GLObject, public Resource
{
	public:
		TextureObject();

		virtual ~TextureObject();

        /*!
         * \brief Bind the texture object
         */
        virtual void bind() const;

        /*!
         * \brief Unbind the texture object
         */
        virtual void unbind() const;

        /*!
         * \brief Allocate texture according to parameters
         */
        virtual void allocateTexture() = 0;

        /*!
         * \brief Load image data in texture object
         */
        virtual void loadImage() = 0;

        void setImage(const std::string& filename = "");

        void setWrapS(GLint wrap);
        GLint getWrapS() const;

        void setWrapT(GLint wrap);
        GLint getWrapT() const;

        void setWrapR(GLint wrap);
        GLint getWrapR() const;

        void setMinFilter(GLint minFilter);
        GLint getMinFilter() const;

        void setMagFilter(GLint magFilter);
        GLint getMagFilter() const;

        void setInternalFormat(GLint internalFormat);
        GLint getInternalFormat() const;

        void setDataFormat(GLenum dataFormat);
        GLenum getDataFormat() const;

        void setDataType(GLenum dataType);
        GLenum getDataType() const;

        bool isAllocated() const;

        bool isImageLoaded() const;

        /*!
         * \brief apply given texture parameters
         */
        void applyParameters();

        /*!
         * \brief set the current active texture unit
         */
        static void setActiveUnit(int unit);

        // TODO enum for texture parameters to make easier setting

	protected:
        virtual GLuint generate() const;

	protected:
        /// specifies the target to which the texture is bound
        GLenum target;

        /// texture wrap parameters
        GLint wrapS;
        GLint wrapT;
        GLint wrapR;

        /// texture filter parameters
        GLint minFilter;
        GLint magFilter;

        /// texture format parameters
        GLint internalFormat;
        GLenum dataFormat;
        GLenum dataType;

        /// indicate if texture is allocated or not
        bool allocated;

        /// indicate if an image has been loaded
        bool imageLoaded;

        /// images filename list (vector in case of cubemap texture)
        std::vector<std::string> imageFilenameList;
};

}

#endif

